<?php use_stylesheet('forms.css') //load css ?>
<div id="nav">
        <ul>
            <a href="<?php echo url_for('sales_index_contacts') ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_menu_contacts.png') ?>Contacts</li></a>
            <a href="<?php echo url_for('sales_index_orders') ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_menu_orders.png') ?>Orders</li></a>
            <a href="<?php echo url_for('sales_index_pnp') ?>"><li class="no_sel"><span style="float: left;"><?php echo image_tag('Icons/ic_menu_products_parts.png') ?></span><span style="float: left; margin: -2px 0 0 0;">Materials</span><span style=" float: left; margin-top: -5px;">&amp; Products</span></li></a>
            <a href="<?php echo url_for('purchase_index') ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_menu_purchase.png') ?>Purchase</li></a>
            <a href="<?php echo url_for('stock_index') ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_menu_stock.png') ?>Stock</li></a>
            <?php if($sf_user->isSuperAdmin()){ ?>
            <a href="<?php echo url_for('admin_index') ?>"><li class="no_sel"><?php echo image_tag('Icons/ic_menu_stock.png') ?>Admin</li></a>
            <?php } ?>
        </ul>
</div>
   
<div id="page">
    <h1>Edit Purchase</h1>
    <a href="<?php echo url_for('purchase_index') ?>" class="bt_back"><img src="<?php echo image_path('Buttons/bt_arrow_back.png') ?>" onmouseover="this.src='<?php echo image_path('Buttons/bt_arrow_back_hov.png') ?>'" onmouseout="this.src='<?php echo image_path('Buttons/bt_arrow_back.png') ?>'"></a>
    <div id="form"> 
     <form action="<?php echo url_for('purchase/updatePurchase?id='.$purchase->getId()) ?>" method="post">
         <fieldset style="margin-top: -40px;">
             <legend>Purchase</legend>
             <table>
                <tr>
                    <td width="100px">Status</td>
                    <td class="input_small"><?php echo $form['status']->render() ?></td>
                    <td class="left_error"><?php echo $form['status']->renderError() ?></td>
                </tr>
                <tr>
                    <td>Quantity</td>
                    <td class="input_small"><?php echo $form['amount']->render() ?></td>
                    <td class="left_error"><?php echo $form['amount']->renderError() ?></td>
                </tr>
                <tr>
                    <td>Price</td>
                    <td class="input_small"><?php echo $form['price']->render() ?></td>
                    <td class="left_error"><?php echo $form['price']->renderError() ?></td>
                </tr>
                <tr>
                    <td>Supplier</td>
                    <!--- Give a list of all suppliers with the first option being the supplier that has already been assigned to the purchase  --->
                    <?php $purchase = $form->getObject(); ?>
                    <?php if($purchase->getSupplierId() != null){
                        $currentSupplier = ContactTable::getInstance()->findOneBy('id', $purchase->getSupplierId());
                    } ?>
                    <?php $suppliers = ContactTable::getInstance()->findBy('category_name', 'supplier') ?>
                    <td><select name="supplier">
                            <?php if($currentSupplier != null) { ?>
                                <option value="<?php echo $currentSupplier->getId() ?>"><?php echo $currentSupplier->getName() ?></option>
                            <?php } ?>
                            <option value="<?php echo null ?>"></option>                                  
                            <?php foreach($suppliers as $supplier){?>
                                <?php if($supplier != $currentSupplier){ ?>
                                    <option value="<?php echo $supplier->getId() ?>"><?php echo $supplier->getName() ?></option>
                            <?php } } ?>
                        </select>
                    </td>           
                </tr>
            </table>
    <input type="submit" value="" class="ok" title="Confirm"/>
      <!---  <?php if (!$form->getObject()->isNew()): ?>
            &nbsp;<?php echo link_to('Cancel purchase', 'purchase/deletePurchase?id='.$form->getObject()->getId(), array('method' => 'delete', 'confirm' => 'Are you sure?')) ?>
        <?php endif; ?> --->
        <div class="hidden_csrf">
            <?php echo $form['_csrf_token']->renderRow(); ?>
            <?php echo $form['supplier_id']->renderRow(); ?>
            <?php echo $form['material_id']->renderRow(); ?>
            <?php echo $form['date_received']->renderRow(); ?>
        </div>
         </fieldset>
    </form>  
    </div>
</div>

